package com.roger.myHome.util;

import com.roger.myHome.entity.LoginUser;
import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class UserHelper {

    public LoginUser getLoginUser(HttpServletRequest request){
        String header = request.getHeader(Constants.HEADER);
        Claims claims = JwtUtil.checkToken(header);
        //Object userId = claims.get(Constants.USER_ID);
        //claims.get("username");
        LoginUser loginUser = new LoginUser();
        loginUser.setLoginName(claims.get("loginName").toString());
        loginUser.setId(Long.valueOf(claims.get(Constants.USER_ID).toString()));
        return loginUser;
    }

}
